package com.lovi.myusercenter.exception;

import com.lovi.myusercenter.common.ErrorCode;

/**
 * 自定义业务异常类，方便优雅的抛出
 */
public class BusinessException extends RuntimeException{
    /**
     * 错误码
     */
    private final int code;
    /**
     * 更详细的错误描述，可以填写也可以不填写
     */
    private final String description;

    public BusinessException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.description = null;
    }

    public BusinessException(ErrorCode errorCode, String description) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

}
